/**
 * 路由配置文件（方案 B：不使用懒加载）
 *
 * @file frontend/src/routes/index-no-lazy.tsx
 * @description 所有页面组件一次性加载，路由切换时不再出现“第一次加载”的刷新/等待
 *
 * 特点：
 * 1. 不使用 React.lazy / Suspense，消除首次进入页面的加载等待
 * 2. 保持类型安全和 IDE 跳转
 * 3. 复用优化版的路由分组和结构
 */

import React, { ComponentType } from 'react';
import { RouteObject, Navigate } from 'react-router-dom';

// ============================================================================
// 辅助函数
// ============================================================================

/**
 * 创建路由对象的辅助函数（不使用懒加载）
 * @param path 路由路径
 * @param Component 页面组件
 */
const createRoute = (
  path: string,
  Component: ComponentType<any>
): RouteObject => ({
  path,
  element: <Component />,
});

/**
 * 创建重定向路由的辅助函数
 * @param from 源路径
 * @param to 目标路径
 */
const createRedirect = (from: string, to: string): RouteObject => ({
  path: from,
  element: <Navigate to={to} replace />,
});

// ============================================================================
// 页面组件（直接导入，不使用懒加载）
// ============================================================================

// 主要页面
import Welcome from '../pages/Welcome';
import Main from '../pages/Main';
import NetPyNE from '../components/NetPyNE/NetPyNE';

// 模型定义
import Populations from '../pages/Populations';
import SynMechs from '../pages/SynMechs';
import ConnRules from '../pages/ConnRules';
import SubcellConnRules from '../pages/SubcellConnRules';
import StimSources from '../pages/StimSources';
import StimTargets from '../pages/StimTargets';

// 仿真配置
import SimulationConfigGeneral from '../pages/SimulationConfigGeneral';
import SimulationConfigRecord from '../pages/SimulationConfigRecord';
import SimulationConfigNetwork from '../pages/SimulationConfigNetwork';
import SimulationConfigNetworkV2 from '../pages/SimulationConfigNetworkV2';
import SimulationConfigNetworkEditor from '../pages/SimulationConfigNetworkEditor';
import SimulationConfigSave from '../pages/SimulationConfigSave';
import SimulationConfigSaveV2 from '../pages/SimulationConfigSaveV2';

// 绘图设置
import PlotSettingsRaster from '../pages/PlotSettingsRaster';
import PlotSettingsTrajectory from '../pages/PlotSettingsTrajectory';
import PlotSettingsLFP from '../pages/PlotSettingsLFP';

// 反应扩散
import ReactionDiffusionRegion from '../pages/ReactionDiffusionRegion';
import ReactionDiffusionEmpty from '../pages/ReactionDiffusionEmpty';

// 导入功能
import ImportNeuroML from '../pages/ImportNeuroML';
import ImportPythonDialog from '../pages/ImportPythonDialog';

// 实验管理
import ExperimentManager from '../pages/ExperimentManager';

// 对话框
import SelectFolderDialog from '../pages/SelectFolderDialog';
import OpenJSONDialog from '../pages/OpenJSONDialog';
import SaveJSONDialog from '../pages/SaveJSONDialog';
import SaveJSONDialogOptions from '../pages/SaveJSONDialogOptions';
import DeleteConfirmDialog from '../pages/DeleteConfirmDialog';

// 特殊页面
import GeppettoTest from '../pages/GeppettoTest';

// ====================================================================================
// 路由配置
// ============================================================================

/**
 * 主要页面路由
 */
const mainRoutes: RouteObject[] = [
  // 首页和主配置
  createRoute('/', Welcome),
  createRoute('/cell-config', Main),
  createRoute('/netpyne', NetPyNE),
  
  // 模型定义
  createRoute('/populations', Populations),
  createRoute('/syn-mechs', SynMechs),
  createRoute('/conn-rules', ConnRules),
  createRoute('/subcell-conn-rules', SubcellConnRules),
  createRoute('/stim-sources', StimSources),
  createRoute('/stim-targets', StimTargets),
  
  // 仿真配置
  createRoute('/simulation-config-general', SimulationConfigGeneral),
  createRoute('/simulation-config-record', SimulationConfigRecord),
  createRoute('/simulation-config-network', SimulationConfigNetwork),
  createRoute('/simulation-config-network-v2', SimulationConfigNetworkV2),
  createRoute('/simulation-config-network-editor', SimulationConfigNetworkEditor),
  createRoute('/simulation-config-save', SimulationConfigSave),
  createRoute('/simulation-config-save-v2', SimulationConfigSaveV2),
  
  // 绘图设置
  createRoute('/plot-settings-raster', PlotSettingsRaster),
  createRoute('/plot-settings-trajectory', PlotSettingsTrajectory),
  createRoute('/plot-settings-lfp', PlotSettingsLFP),
  
  // 反应扩散
  createRoute('/reaction-diffusion-region', ReactionDiffusionRegion),
  createRoute('/reaction-diffusion-empty', ReactionDiffusionEmpty),
  
  // 导入功能
  createRoute('/import-neuroml', ImportNeuroML),
  createRoute('/import-python', ImportPythonDialog),
  
  // 实验管理
  createRoute('/experiment-manager', ExperimentManager),
  
  // 对话框
  createRoute('/select-folder', SelectFolderDialog),
  createRoute('/open-json', OpenJSONDialog),
  createRoute('/save-json', SaveJSONDialog),
  createRoute('/save-json-options', SaveJSONDialogOptions),
  createRoute('/delete-confirm', DeleteConfirmDialog),
  
  // 特殊页面
  createRoute('/geppetto-test', GeppettoTest),
];

/**
 * 兼容性路由（重定向）
 */
const legacyRoutes: RouteObject[] = [
  createRedirect('/synaptic-mechanisms', '/syn-mechs'),
  createRedirect('/connectivity-rules', '/conn-rules'),
  createRedirect('/subcellular-connectivity', '/subcell-conn-rules'),
  createRedirect('/stimulation-sources', '/stim-sources'),
  createRedirect('/stimulation-targets', '/stim-targets'),
  createRedirect('/plot-settings-traces', '/plot-settings-trajectory'),
  createRedirect('/reaction-diffusion-extracellular', '/reaction-diffusion-empty'),
];

/**
 * Frame 路由（设计图编号重定向）
 */
const frameRoutes: RouteObject[] = [
  createRedirect('/frame/8', '/cell-config'),
  createRedirect('/frame/10', '/simulation-config-general'),
  createRedirect('/frame/13', '/plot-settings-raster'),
  createRedirect('/frame/14', '/plot-settings-trajectory'),
  createRedirect('/frame/15', '/reaction-diffusion-region'),
  createRedirect('/frame/16', '/plot-settings-lfp'),
  createRedirect('/frame/17', '/reaction-diffusion-empty'),
  createRedirect('/frame/18', '/simulation-config-record'),
  createRedirect('/frame/19', '/simulation-config-network'),
  createRedirect('/frame/20', '/simulation-config-save'),
  createRedirect('/frame/21', '/simulation-config-network-v2'),
  createRedirect('/frame/22', '/simulation-config-save-v2'),
  createRedirect('/frame/23', '/import-neuroml'),
  createRedirect('/frame/24', '/simulation-config-network-editor'),
  createRedirect('/frame/25', '/experiment-manager'),
  createRedirect('/frame/26', '/select-folder'),
  createRedirect('/frame/27', '/open-json'),
  createRedirect('/frame/28', '/save-json'),
  createRedirect('/frame/29', '/delete-confirm'),
  createRedirect('/frame/30', '/save-json-options'),
  createRedirect('/frame/31', '/import-python'),
];

// ====================================================================================
// 导出路由配置
// ============================================================================

/**
 * 应用的完整路由配置（方案 B：不使用懒加载）
 */
const routes: RouteObject[] = [
  ...mainRoutes,
  ...legacyRoutes,
  ...frameRoutes,
];

export default routes;

// 导出分类路由（可选）
export {
  mainRoutes,
  legacyRoutes,
  frameRoutes,
};

